home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
HyperLib 1997 Winter - Disc 1
/
HYPERLIB-1997-Winter-CD1.ISO.7z
/
HYPERLIB-1997-Winter-CD1.ISO
/
オンラインウェア
/
PRG
/
LZSS Res 2.1 ト.sit
/
LZSS Res 2.1 ƒ
/
LZSS Example ƒ
/
LZSSExample.c
next >
Wrap
C/C++ Source or Header
|
1993-07-04
|
3KB
|
169 lines
/*
* Copyright ゥ 1994 Dmitry Boldyrev
* All rights reserved
*/
#include <Dialogs.h>
#include <Events.h>
#include <Fonts.h>
#include <Memory.h>
#include <Menus.h>
#include <OSEvents.h>
#include <QuickDraw.h>
#include <Traps.h>
#include <Palettes.h>
#include "::LZSS Lib ト:LZSS-Lib.h"
RgnHandle gOldVisRgn;
static void HideMenuBar(GrafPtr grafPort)
{
RgnHandle newVisRgn;
GrafPtr savePort;
GetPort(&savePort);
SetPort(grafPort);
gOldVisRgn = NewRgn();
CopyRgn(grafPort->visRgn, gOldVisRgn);
newVisRgn = NewRgn();
RectRgn(newVisRgn, &grafPort->portRect);
CopyRgn(newVisRgn, grafPort->visRgn);
DisposeRgn(newVisRgn);
SetPort(savePort);
}
static void ShowMenuBar(GrafPtr grafPort)
{
GrafPtr savePort;
RgnHandle junkRgn;
GetPort(&savePort);
SetPort(grafPort);
junkRgn = NewRgn();
CopyRgn(gOldVisRgn, junkRgn);
DiffRgn(grafPort->visRgn, junkRgn, junkRgn);
FillRgn(junkRgn, black);
DisposeRgn(junkRgn);
CopyRgn(gOldVisRgn, grafPort->visRgn);
DisposeRgn(gOldVisRgn);
gOldVisRgn = NULL;
DrawMenuBar();
}
static void HeapInit(long stack, short masters)
{
SetApplLimit(GetApplLimit() - stack);
MaxApplZone();
while (masters-- > 0)
MoreMasters();
}
static void InitToolBox(void)
{
EventRecord event;
short i;
InitGraf((Ptr) &qd.thePort);
InitFonts();
InitWindows();
InitMenus();
InitPalettes();
TEInit();
InitDialogs(NULL);
FlushEvents(everyEvent, 0);
InitCursor();
for (i = 0; i < 4; i++)
EventAvail(everyEvent, &event);
}
static void CenterRect(Rect srcRect, Rect* dstRect)
{
short width = (dstRect->right - dstRect->left);
short height = (dstRect->bottom - dstRect->top);
dstRect->left = srcRect.left + (((srcRect.right - srcRect.left) / 2) - (width / 2));
dstRect->top = srcRect.top + (((srcRect.bottom - srcRect.top) / 2) - (height / 2));
dstRect->right = dstRect->left + width;
dstRect->bottom = dstRect->top + height;
}
// loadTime in ticks (1/60s)
static void StatisticsMenu(Size pSize, long loadTime)
{
DialogPtr dlog;
short itemHit;
Str255 pSizeStr, loadTimeStr;
NumToString(pSize/1024, pSizeStr);
NumToString((loadTime * 1000) / 60, loadTimeStr);
ParamText(pSizeStr, loadTimeStr, "¥p", "¥p");
dlog = GetNewDialog(128, nil, (WindowPtr)-1);
do {
ModalDialog(nil, &itemHit);
} while (itemHit != ok);
}
static Boolean WaitKey()
{
EventRecord theEvent;
GetNextEvent(everyEvent, &theEvent);
return (theEvent.what == keyDown);
}
void main(void)
{
PicHandle pic;
Rect r;
WindowPtr theWindow;
PaletteHandle hPalette;
long loadTime;
Size pictSize;
HeapInit(0, 4);
InitToolBox();
InitLZSSRes();
if ((hPalette = GetNewPalette(128)) == nil) // Load new palette
ExitToShell();
loadTime = TickCount();
if ((pic = GetPicture(128)) == nil) // Picture resource not found!
ExitToShell();
loadTime = TickCount() - loadTime;
pictSize = GetHandleSize(pic);
if ((theWindow = GetNewCWindow(128, nil, (WindowPtr)-1)) == nil)
ExitToShell();
SizeWindow(theWindow, screenBits.bounds.right, screenBits.bounds.bottom, true);
MoveWindow(theWindow, 0, 0, false);
ShowWindow(theWindow);
HideMenuBar(theWindow);
SetPort(theWindow);
FillRect(&theWindow->portRect, black);
SetPalette(theWindow, hPalette, true);
r = (*pic)->picFrame;
CenterRect(theWindow->portRect, &r);
DrawPicture(pic, &r);
while (!WaitKey());
ShowMenuBar(theWindow);
DisposeWindow(theWindow);
RestoreDeviceClut(nil);
StatisticsMenu(pictSize, loadTime);
ReleaseResource((Handle)pic);
}